package com.yzyz.web.controller.visitor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.yzyz.bean.route.RouteBean;
import com.yzyz.service.IRouteService;

/**
 * 访客预定行程的预检查
 * 主要是检查预定的行程是否可用
 * @author david.sun
 * @date 2010-7-12
 */
public class PreBookController extends AbstractController {

	private IRouteService routeService;
	
	public void setRouteService(IRouteService routeService) {
		this.routeService = routeService;
	}

	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		RouteBean route = (RouteBean)this.routeService.find(Integer.valueOf(request.getParameter("routeId")));
		if(route == null || !route.isAvailable() || route.isDeleted()) {
			ModelAndView mv = new ModelAndView("/Error/error.jsp");
			mv.addObject("errorMsg", "抱歉！您预定的行程不存在！");
			return mv;
		}
		ModelAndView mv = new ModelAndView("/Book/book.jsp");
		mv.addObject("route", route);
		return mv;
	}

}
